﻿using Microsoft.AspNetCore.Mvc;
using MVC_System.DTO.FinishedProduct;
using MVC_System.DTO.RawMaterial;
using Newtonsoft.Json;
using NuGet.Common;
using WMS_MAV;

namespace MVC_System.Controllers
{
	public class FinishedProductController : Controller
	{
        private readonly IConfiguration _configuration;
        public FinishedProductController(IConfiguration configuration)
        {
            _configuration = configuration;
        }
        public IActionResult FinishedShow()
		{
			return View();
		}
        public IActionResult FinishedAdd()
		{
			return View();
		}
        public IActionResult FinishedUpdate()
		{
			return View();
		}
        public IActionResult FinishedUpdateDetail()
        {
            return View();
        }

        /// <summary>
        /// 成品显示
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task<ActionResult> FinishedProductShow(FinishedProductShowDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "RawApi/api/FinishedProducts/FinishedProductsShow?PageIndex=" + dto.pageIndex + "&PageSize=" + dto.pageSize + "&finishedProductNumbering=" + dto.finishedProductNumbering + "&finishedProductState=" + dto.finishedProductState;
            var respomse = await client.GetAsync(url);
            return Json(respomse);
        }

        public async Task<ActionResult> FinishedProductAdd(FinishedProductAddDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "RawApi/api/FinishedProducts/FinishedProductsAdd";
            var respomse = await client.PostAsync(url,dto.Data);
            return Json(respomse);
        }
        public async Task<ActionResult> FinishedProductAddMondel(FinishedProductMondelDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "RawApi/api/FinishedProducts/FinishedProductsMondel?id=" + dto.id;
            var respomse = await client.GetAsync(url);
            return Json(respomse);
        }
        public async Task<ActionResult> FinishedProductUpdate(FinishedProductUpdateDTO dto,string token)
        {
            HttpClientWrapper client = new HttpClientWrapper(token);
            string url = _configuration["Url"] + "RawApi/api/FinishedProducts/FinishedProductsUpdate";
            string list = JsonConvert.SerializeObject(dto);
            var respomse = await client.PostAsync(url, list);
            return Json(respomse);
        }
        public async Task<ActionResult> FinishedProductDelete(FinishedProductDeleteDTO dto, string token)
        {
            HttpClientWrapper client = new HttpClientWrapper(token);
            string url = _configuration["Url"] + "RawApi/api/FinishedProducts/FinishedProductsDelete";
            string list = JsonConvert.SerializeObject(dto);
            var respomse = await  client.PostAsync(url, list);
            return Json(respomse);
        }
        public async Task<ActionResult> FinishedProductDeletePi(FinishedProductDeletePiDTO dto, string token)
        {
            HttpClientWrapper client = new HttpClientWrapper(token);
            string url = _configuration["Url"] + "RawApi/api/FinishedProducts/FinishedProductsDeletePi";
            string list = JsonConvert.SerializeObject(dto);
            var respomse = await  client.PostAsync(url, list);
            return Json(respomse);
        }
    }
}
